package com.ruoyi.web.controller.selfBookingConfig;


import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SelfBookingConfig;
import com.ruoyi.system.service.ISelfBookingConfigService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 自助预订配置Controller
 *
 * @author ruoyi
 * @date 2025-05-16
 */
@Api(tags="自助预订配置")
@RestController
@RequestMapping("/system/selfBookingConfig")
public class SelfBookingConfigController extends BaseController
{
    @Autowired
    private ISelfBookingConfigService selfBookingConfigService;

    /**
     * 查询自助预订配置列表
     */
    @ApiOperation("查询自助预订配置列表")
    @PreAuthorize("@ss.hasPermi('system:config:list')")
    @GetMapping("/list")
    public TableDataInfo list(@RequestParam(required = false) String storeName)
    {
        startPage();
        List<SelfBookingConfig> list = selfBookingConfigService.selectSelfBookingConfigListByName(storeName);
        return getDataTable(list);
    }

    /**
     * 导出自助预订配置列表
     */
    @ApiOperation("导出自助预订配置列表")
    @PreAuthorize("@ss.hasPermi('system:config:export')")
    @Log(title = "自助预订配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, @RequestParam(required = false) String storeName)
    {
        List<SelfBookingConfig> list = selfBookingConfigService.selectSelfBookingConfigListByName(storeName);
        ExcelUtil<SelfBookingConfig> util = new ExcelUtil<SelfBookingConfig>(SelfBookingConfig.class);
        util.exportExcel(response, list, "自助预订配置数据");
    }

    /**
     * 获取自助预订配置详细信息
     */
    @ApiOperation("获取自助预订配置详细信息")
    @PreAuthorize("@ss.hasPermi('system:config:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(selfBookingConfigService.selectSelfBookingConfigById(id));
    }

    /**
     * 新增自助预订配置
     */
    @ApiOperation("新增自助预订配置")
    @PreAuthorize("@ss.hasPermi('system:config:add')")
    @Log(title = "自助预订配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SelfBookingConfig selfBookingConfig)
    {
        return toAjax(selfBookingConfigService.insertSelfBookingConfig(selfBookingConfig));
    }

    /**
     * 修改自助预订配置
     */
    @ApiOperation("修改自助预订配置")
    @PreAuthorize("@ss.hasPermi('system:config:edit')")
    @Log(title = "自助预订配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SelfBookingConfig selfBookingConfig)
    {
        return toAjax(selfBookingConfigService.updateSelfBookingConfig(selfBookingConfig));
    }

    /**
     * 删除自助预订配置
     */
    @ApiOperation("删除自助预订配置")
    @PreAuthorize("@ss.hasPermi('system:config:remove')")
    @Log(title = "自助预订配置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(selfBookingConfigService.deleteSelfBookingConfigByIds(ids));
    }
}
